<?php

require_once '../app/core/models/BaseDao.php';
require_once '../app/core/db/DBUtil.class.php';

class AreaDictDao extends BaseDao {
	
	private $tableName = "area_dicts";
	
	public function save($area){
		$area[3] = str_replace('"','',$area[3]);
		$area[3] = iconv('gb2312','utf-8',trim($area[3]));
		
		$param = array($area[0], $area[1],$area[2],$area[3]);
//		print_r($param);die;
        $sql = "insert into $this->tableName (id, level, parent,title, is_delete, modified, created) values (?,?,?,?,0,now(),now())";
        return $this->dbUtil->ExecuteQuery($sql, $param);
	}
	
	public function getAreaDicts($params){
		$sql = "select * from $this->tableName where parent = ? and level = ? and is_delete = 0 ";
        return $this->dbUtil->SelectData($sql, $params);
	}
	
	public function getAreaById($id){
		$param = array($id);
		$sql = "select * from $this->tableName where id = ? and is_delete = 0 ";
        return $this->dbUtil->SelectData($sql, $param);
	}
	
	public function getAllProvince(){
		$params = array();
		$sql = "select * from $this->tableName where level = 1 and is_delete = 0 ";
        return $this->dbUtil->SelectData($sql, $params);
	}
	
}
?>